import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/Login.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/fsMainPage',
        name: 'fsMainPage',
        component: () => import('../views/FsMainPage.vue'),
        meta: {
            title: '首页'
        }
    },
    {
        path: '/fsAddPage',
        name: 'fsAddPage',
        component: () => import('../views/FsAddPage.vue'),
        meta: {
            title: '人员入库'
        }
    },
    {
        path: '/fsAddListPage',
        name: 'fsAddListPage',
        component: () => import('../views/FsAddListPage.vue'),
        meta: {
            title: '人员入库列表'
        }
    },
    {
        path: '/fsModifyPage',
        name: 'fsModifyPage',
        component: () => import('../views/FsModifyPage.vue'),
        meta: {
            title: '人员修改'
        }
    },
    {
        path: '/fsTransferPage',
        name: 'fsTransferPage',
        component: () => import('../views/FsTransferPage.vue'),
        meta: {
            title: '人员调动'
        }
    },
    {
        path: '/fsDetailPage',
        name: 'fsDetailPage',
        component: () => import('../views/FsDetailPage.vue'),
        meta: {
            title: '人员履历'
        }
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

// 添加全局前置守卫
router.beforeEach((to, from, next) => {
    // 如果路由元信息中有title，则设置文档标题
    if (to.meta.title) {
        document.title = to.meta.title as string
    }
    next()
})

export default router
